/*
 * HealthCheckup.java
 *
 * Created on August 31, 2008, 7:41 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Project.bussiness;

import Project.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author Hao Hao
 */
public class HealthCheckup {
    
    /** Creates a new instance of HealthCheckup */
    private int HealthCheckupID;
    private String Date;
    private int PatientID;
    private int DoctorID;
    private String StateOfHealth;
    private float Price;

    public int getHealthCheckupID() {
        return HealthCheckupID;
    }

    public void setHealthCheckupID(int HealthCheckupID) {
        this.HealthCheckupID = HealthCheckupID;
    }

    public String getDate() {
        return Date;
    }

    public void setDate(String Date) {
        this.Date = Date;
    }

    public int getPatientID() {
        return PatientID;
    }

    public void setPatientID(int PatientID) {
        this.PatientID = PatientID;
    }

    public int getDoctorID() {
        return DoctorID;
    }

    public void setDoctorID(int DoctorID) {
        this.DoctorID = DoctorID;
    }

    public String getStateOfHealth() {
        return StateOfHealth;
    }

    public void setStateOfHealth(String StateOfHealth) {
        this.StateOfHealth = StateOfHealth;
    }
    
    public float getPrice() {
        return Price;
    }

    public void setPrice(float Price) {
        this.Price = Price;
    }
    public static Vector getAllHealthCheckup() throws SQLException
    {
        Vector v = new Vector();
        try {
        ResultSet rs = DBHelper.executeQuery("spGetAllHealthCheckups");
            while(rs.next()){
                HealthCheckup h = new HealthCheckup();
                h.setHealthCheckupID(rs.getInt(1));  
                h.setDate(rs.getString(2));
                h.setPatientID(rs.getInt(3));
                h.setDoctorID(rs.getInt(4));
                h.setStateOfHealth(rs.getString(5));
                h.setPrice(rs.getFloat(6));
                v.add(h);
            }
        } catch(SQLException sqle) {
            throw sqle;
        }
        return v;        
    }   
    
    public static Vector getHealthCheckupById(int id) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(new Integer(id));
            ResultSet rs = DBHelper.executeQuery("spSearchHealthCheckupById", paramList);
            
            while(rs.next()){
                HealthCheckup h = new HealthCheckup();
                h.setHealthCheckupID(rs.getInt(1));  
                h.setDate(rs.getString(2));
                h.setPatientID(rs.getInt(3));
                h.setDoctorID(rs.getInt(4));
                h.setStateOfHealth(rs.getString(5));
                h.setPrice(rs.getFloat(6));
                v.add(h);
            }
        } catch(SQLException sqle) {
            // Handle exception            
            throw sqle;
        }   
        return v;
    }     
    
    public static Vector getHealthCheckupByPatientId(int id) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(new Integer(id));
            ResultSet rs = DBHelper.executeQuery("spSearchHealthCheckupByPatientID", paramList);
            
            while(rs.next()){
                HealthCheckup h = new HealthCheckup();
                h.setHealthCheckupID(rs.getInt(1));  
                h.setDate(rs.getString(2));
                h.setPatientID(rs.getInt(3));
                h.setDoctorID(rs.getInt(4));
                h.setStateOfHealth(rs.getString(5));
                h.setPrice(rs.getFloat(6));
                v.add(h);
            }
        } catch(SQLException sqle) {
            // Handle exception            
            throw sqle;
        }   
        return v;
    }       
    
    public static Vector getHealthCheckupByCaseID(int id) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(new Integer(id));
            ResultSet rs = DBHelper.executeQuery("spSearchHealthCheckupByCaseID", paramList);
            
            while(rs.next()){
                HealthCheckup h = new HealthCheckup();
                h.setHealthCheckupID(rs.getInt(1));  
                h.setDate(rs.getString(2));
                h.setPatientID(rs.getInt(3));
                h.setDoctorID(rs.getInt(4));
                h.setStateOfHealth(rs.getString(5));
                h.setPrice(rs.getFloat(6));
                v.add(h);
            }
        } catch(SQLException sqle) {
            // Handle exception            
            throw sqle;
        }   
        return v;
    }     

    public static int updateHealthCheckup(int id, HealthCheckup h) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(new Integer(id));
            paramList.add(h.Date);
            paramList.add(h.PatientID);
            paramList.add(h.DoctorID);
            paramList.add(h.StateOfHealth);
            paramList.add(h.Price);
            i=DBHelper.executeUpdate("spUpdateHealthCheckup",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }          

    public static int insertHealthCheckup(HealthCheckup h) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(h.Date);
            paramList.add(h.PatientID);
            paramList.add(h.DoctorID);
            paramList.add(h.StateOfHealth);
            paramList.add(h.Price);
            i=DBHelper.executeUpdate("spInsertHealthCheckup",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }     

    public static int deleteHealthCheckup(int id) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(new Integer(id));
            i=DBHelper.executeUpdate("spDeleteHealthCheckup",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }       


}
